package com.kantboot.global.event;

import com.kantboot.global.event.annotation.GlobalEventOn;
import com.kantboot.util.common.http.HttpRequestHeaderUtil;
import com.kantboot.util.core.redis.RedisUtil;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/testEvent")
public class Test {

    @Resource
    private GlobalEvent globalEvent;

    @Resource
    private RedisUtil redisUtil;

    @Resource
    private HttpRequestHeaderUtil httpRequestHeaderUtil;

    @RequestMapping("/test")
    public String test() {
        // 开始事件
        long start = System.currentTimeMillis();
        globalEvent.emit("test", "999999","888");
        redisUtil.set("test", "99999922");
        System.err.println("耗时：" + (System.currentTimeMillis() - start));
        return "test";
    }

    @GlobalEventOn(code="test")
    public String test2(String value,String value2) {
        System.err.println(httpRequestHeaderUtil.getIp());
        System.err.println("----");
        System.err.println(value);
        System.err.println(value2+"---");
        System.err.println(redisUtil.get("test"));
        return value;
    }


}
